# konrad.smolinski@gmail.com
# date: 		Nov 2010
# last update: 13/05/2011
#
# info:
# 	We look at the random coeficient model with ordered, discrete covariates
#	i.e. univariate endogenous variable X with discrete support X[1] < X[2] < ... < X[K];
#	this set up gives rise to very particular structure where the
#	elements of integrand are 'tiramisu' slices
# 
#	clock-wise enumeration give rise to a simple, circular coding with length(sequence)=K
#	for K=5 we have: (11000,11100,11110,1111 etc) 
#
# ------------------------------------------------------------------
# Set Up
# rcBase() :
# 	generates ones in a circular fasion i.e: for K=3
#	sequence is: 100,110,111,011,001,000

rcBase <- function(K){
	supp <- rep(0,K)
	supMat <- NULL

	for(i in 1:K){
		supp[i] <- 1
		supMat <- rbind(supMat,supp)
	}

	for(i in 1:K){
		supp[i] <- 0
		supMat <- rbind(supMat,supp)
	}
	rownames(supMat) <- paste("a",1:(2*K),sep="")

return(supMat)
}

# ---- Validate:
valCond <- FALSE
if(valCond){
 supMat <- rcBase(K=2)
 supMat
}
# ------------------------------------------------------------------
rcBaseIdx <- function(K) 1:(2*K)

# --- Validate
codeVal <- FALSE
if(codeVal){ 
	cat("\n Validate: rcBaseIdx() : \n\n")
	baseIdx <- rcBaseIdx(K=3)
	baseIdx
}
# ------------------------------------------------------------------
